package com.luych.toolbox.automation.service.core.executor;

import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.SftpException;
import com.luych.toolbox.automation.service.core.connection.SshConnection;
import com.luych.toolbox.common.service.tool.Cmd;

import java.io.InputStream;

public class FileExecutor implements TaskExecutor<SshConnection> {

    private final InputStream inputStream;

    public FileExecutor(InputStream inputStream) {
        this.inputStream = inputStream;
    }

    @Override
    public String execute(SshConnection target, String... args) {
        try {
            Cmd.uploadRemote(target.getHost(), target.getPort(), target.getUser(), target.getPass(), inputStream, args[0]);
            return "";
        } catch (JSchException | SftpException e) {
            throw new RuntimeException(e);
        }
    }
}
